window.onload = function () {
    getmenu();
};
var ctrlflag = 0;                           //请求flag
var b1nums = document.getElementById('b1nums'),     //行1数
    b2nums = document.getElementById('b2nums'),     //行2数
    b3nums = document.getElementById('b3nums'),     //行3数
    b4nums = document.getElementById('b4nums'),     //行4数
    reload = document.getElementById('reload'),     //刷新
    sportbetrecord = document.getElementById('sportbetrecord'),     //投注记录
    sportaccrecord = document.getElementById('sportaccrecord'),     //账户历史
    sportresult = document.getElementById('sportresult'),       //赛果查询
    jpbox = document.getElementById('jpbox'),       //跳窗
    jpmain = document.getElementById('jp-main'),        //跳窗main
    jpclose = document.getElementById('jp-title-close'),       //jpclose
    jptitle = document.getElementById('jp-title-name');         //jptitle

function ajaxget(url, callback) {
    var xmlhttp;
    if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        console.log("不支持ajax");
    }
    xmlhttp.open('GET', url, true);
    xmlhttp.send();
    console.log('已发送ajax');
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
                console.log('已得到数据');
                var ajaxgetdata = JSON.parse(xmlhttp.responseText);
                callback(ajaxgetdata);
            } else {
                console.log('getmenu出错');
            }
        }
    }
}

function getmenu() {        //初始化ajax
    ajaxget('http://27.151.56.3:5000/todaymenu', function (json_data) {
        var jsondata = json_data;
        b1nums.innerHTML = jsondata.ic;
        b2nums.innerHTML = jsondata.tc;
        b3nums.innerHTML = jsondata.ec;
        b4nums.innerHTML = jsondata.pc;
    });
}
//界面功能按钮
reload.onclick = function () {
    window.location.reload();
};
sportbetrecord.onclick = function () {
    alert('暂未开通');
};
sportaccrecord.onclick = function () {
    alert('暂未开通');
};
sportresult.onclick = function () {
    alert('暂未开通');
};

//jpbox
//jpbox功能按键
jpclose.onclick = function () {
    jpbox.style.display = 'none';
    jpmain.innerHTML = '';
};
$("#jp-title-return").click(function () {

})

//ajax
$("#betboxul li").on("click", function () {
    var that = this;
    ajaxget('http://27.151.56.3:5000/' + this.id.toString(), function (json_data) {
        var jsondata = json_data;
        var jpboxwrite = '<ul>';
        for (var i = 0; i < jsondata.s.length; i++) {
            jpboxwrite += '<li id="' + jsondata.s[i].i + '" pageType = "5"><span class="jpmainpj">' + jsondata.s[i].n + '</span><span class="jpmainnum">' + jsondata.s[i].c + '</span></li>';
        }
        jpboxwrite += '</ul>';
        jpmain.innerHTML = jpboxwrite;
        jptitle.innerHTML = that.innerHTML;
        jpbox.style.display = 'block';
    });
});




$("#jp-main li").on("click", function () {
    var pagetypes = this.getAttribute('pagetype');
    var sportids = this.id;
});

